import 'package:dio/dio.dart';
import 'package:flutter_chubao/tools/tool_app/app_dio_exceptions.dart';

class AppDioResponse {
  late bool ok;
  dynamic data;
  AppDioException? error;

  // ignore: unused_element
  AppDioResponse._internal({this.ok = false});

  AppDioResponse.success(this.data) {
    this.ok = true;
  }

  AppDioResponse.failure({String? errorMsg, int? errorCode}) {
    this.error = BadRequestException(message: errorMsg, code: errorCode);
    this.ok = false;
  }

  AppDioResponse.failureFormResponse({dynamic data}) {
    this.error = BadResponseException(data);
    this.ok = false;
  }

  AppDioResponse.failureFromError([AppDioException? error]) {
    this.error = error ?? UnknownException();
    this.ok = false;
  }
}
